package tankgame03;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author DCSGO
 * @version 1.0
 */

@SuppressWarnings({"all"})
public class TankGame03 extends JFrame {
    private MyPanel mp;

    public static void main(String[] args) {
        TankGame03 tankGame03 = new TankGame03();

    }

    public TankGame03() {
        mp = new MyPanel();
        this.setSize(1000 + 16 + 260, 750 + 39);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.add(mp);
        this.addKeyListener(mp);

        new Thread(mp).start();
        for (int i = 0; i < mp.enemyTanks.size(); i++) {
            new Thread(mp.enemyTanks.get(i)).start();
        }

        //添加 窗口监听器 用于监听关闭中
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.save();//保存积分
                LastEnemyTanks.save(mp.enemyTanks);//保存坦克信息
                System.exit(0);
            }
        });

    }
}
